<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Page extends BIT_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */

	public function __construct()
	{
		parent::__construct();
		$this->header_views = array('admin/header');
		$this->footer_views = array('admin/footer');
		
		// Check if user is loggedin
		if(! $this->isloggedin())
		{
			redirect('admin/login');
		}
	}
	private function isloggedin(){return (isset($this->session->userdata) && $this->session->userdata('loggedin')===TRUE);}

	public function edit($pageid)
	{
		$this->view_data['message']="";

		if($this->input->post('wysi')){
			$this->db->update('pages', array('id'=>$pageid, 'html'=>$this->input->post('wysi')));
			$this->view_data['message'] = "Sparat!";
		}

		$pagedata = $this->db->get_where('pages', array('id' => $pageid), 1)->result();

		foreach($pagedata[0] as $k=>$v){
			$this->view_data[$k]=$v;
		}
		$this->v('admin/page');
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */